/***************************************************************************
 * 上传图片
 *
 * @returns {Boolean}
 */
function ajaxFileUpload(num, ds, showPicFlag) {
    console.log(showPicFlag)
    var filePath = $("#picture" + num).val();
    if (filePath != '') {
        var extStart = filePath.lastIndexOf("\.");
        var supportPicExt = ".BMP|.PNG|.GIF|.JPG|.JPEG";
        var ext = filePath.substring(extStart, filePath.length).toUpperCase();
        if (supportPicExt.lastIndexOf(ext) == -1) {
            $.error("图片限于bmp,png,gif,jpeg,jpg格式");
            $("#uppic" + num).val('');
            return;
        }
        var url = ds + '/file/upload/oss?sourcePic=picture' + num;
        $.ajaxFileUpload({
            url: url,
            secureuri: false,
            fileElementId: 'picture' + num,
            dataType: 'text',
            success: function (result) {
                //ajaxFileUpload返回不支持json,因此需要replace <pre> 标签
                result = $.parseJSON(result.replace(/<.*?>/ig, ""));
                var resultJson = result;
                if ("success" == resultJson.status) {
                    processAfterUpload(resultJson.filePath, resultJson.fileName, ds, num, showPicFlag);
                } else {
                    $.error(resultJson.message);
                }
            },
            error: function (data, status, e) {
                alert(e);
            }
        });
        return false;
    }

}

function processAfterUpload(filePath, fileName, ds, num, showPicFlag) {
    $("#filePath" + num).val(fileName);
    if (showPicFlag) {
        $("#image" + num).attr("src", filePath);
    }

}


